var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    purchase: {
      waitQute: 0,
      quoted: 0,
      winningBid: 0,
      notBid: 0,
      waitCheck: 0,
      checkOk: 0,
      checkFail: 0
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.init();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.init();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  init: function () {
    console.log('获取统计数据');
    let that = this;
    util.request(api.UserIndex).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          purchase: res.data.purchaseStatistics
        });
      }
    });
  },
  openPage: function (event) {
    let type = event.currentTarget.dataset.index;
    switch (type) {
      case '1':
        this.navigateToPurchase(1, '待报价')
        break;
      case '2':
        this.navigateToPurchase(2, '已报价')
        break;
      case '3':
        this.navigateToPurchase(3, '已中标')
        break;
      case '4':
        this.navigateToPurchase(4, '未中标')
        break;
      case '5':
        this.navigateToUcenterQute(1, '送检中')
        break;
      case '6':
        this.navigateToUcenterQute(2, '送检合格')
        break;
      case '7':
        this.navigateToUcenterQute(3, '送检不合格')
        break;
    }
  },
  navigateToPurchase(type, name) {
    wx.setStorageSync('purchase_type', type)
    wx.setStorageSync('purchase_name', name);
    wx.navigateTo({
      url: "/pages/purchase/purchase"
    });
  },
  navigateToUcenterQute(type, name) {
    wx.setStorageSync('quoteSingle_type', type)
    wx.setStorageSync('quoteSingle_name', name);
    wx.navigateTo({
      url: "/pages/ucenter/quoteSingle/quoteSingle"
    });
  },

})